package priv.mk.jdbcUtils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {

	public static Connection getconn() throws ClassNotFoundException,
			SQLException {
		Connection connection;
		// 1.加载驱动类
		Class.forName("oracle.jdbc.driver.OracleDriver");
		// 2.获取连接
		connection = DriverManager.getConnection(
				"jdbc:oracle:thin:@localhost:1521:orcl", "lq", "123");
		return connection;
	}

	public static void close(ResultSet set, Connection connection,
			PreparedStatement prepareStatement) {
		if (set != null)
			try {
				set.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		if (prepareStatement != null)
			try {
				prepareStatement.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		if (connection != null)
			try {
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
	}
}
